package routers

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"shop/handlers"
)

func MiddleWera() gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
		c.Next()
	}
}
func SetupRouter(db *gorm.DB) *gin.Engine {
	r := gin.Default()
	r.Use(MiddleWera())
	shopGroup := r.Group("/shop")
	{
		shopGroup.POST("/add", handlers.Add(db))
		shopGroup.GET("/list", handlers.List(db))
		shopGroup.GET("/detail", handlers.Detail(db))
		shopGroup.POST("/upload")
	}
	return r
}
